package com.example.crmweb.controller;


import com.example.crmweb.entity.Auth;
import com.example.crmweb.service.AuthService;
import com.example.crmweb.service.impl.AuthServiceImpl;
import com.example.crmweb.lang.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 权限控制器
 * </p>
 *
 * @author -CRM-
 * @since 2022-03-18
 */
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Resource
    private AuthServiceImpl service;


    /**
     * 查询所有开启的权限
     * @return
     */
    @GetMapping("/batchGet")
    public Result findAllOpen(){
        List<Auth> allOpen = service.batchDescribe();
        return Result.success(200,"查询成功",allOpen);
    }


    /**
     * 添加权限
     * @param auth
     * @return
     */
    @PostMapping("/create")
    public Result addAuth(Auth auth) {
        return service.create(auth);
    }

    /**
     * 修改权限
     * @param auth
     * @return
     */
    @PutMapping("/move")
    public Result update(Auth auth) {
        return service.modify(auth);
    }

    /**
     * 权限软删除
     * @param id
     * @return
     */
    @DeleteMapping("/cancel/{id}")
    public Result delete(@PathVariable("id") Integer id) {
       return service.delete(id);
    }


    @GetMapping("/search/{id}")
    public Result findChildren(@PathVariable("id") Integer id){
        return service.findChildren(id);
    }
}